﻿using System;
using System.Web;

namespace msBsc.WebUi.Custom
{
    public partial class wfShopForgetTradPws : msBsc.Cls.BPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (this.strAction == "REGIST_STEP1")
            {
                if (this.GetParamHtValue("EMAIL") != string.Empty && this.GetParamHtValue("USER_NME") != string.Empty && this.GetParamHtValue("txtLoginPws") != string.Empty && this.GetParamHtValue("VALIDATE_CDE") != string.Empty)
                {
                    if (this.GetParamHtValue("VALIDATE_CDE") != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
                    {
                        this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                        this.Alert("验证码错误或已过期，请重新录入！");
                        return;
                    }
                     
                    using (Epm.AppLogic.Framework.CDbAccess oCDbAccess = new Epm.AppLogic.Framework.CDbAccess())
                    {
                        System.Data.DataSet ds = oCDbAccess.QueryBySQL("SELECT TOP 1 A.COMM_TENANT_ID,A.CONTACTS_EMAIL,B.LOGIN_PSWD FROM SHP_COMMERCIAL_TENANT_INFO A LEFT OUTER JOIN SYS_USER B ON A.USER_NME=B.USER_NME WHERE A.USER_NME='" + this.GetParamHtValue("USER_NME").Replace("'", "") + "'");
                        if (ds.Tables[0].Rows.Count <= 0)
                        {
                            this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                            this.Alert("您输入的掌柜登录名未找到，请重新录入！");
                            return;
                        }


//                        System.Data.DataSet ds3 = oCDbAccess.QueryBySQL(@"
//    SELECT 
//    A.COMM_TENANT_NME
//    ,A.CONTACTS_EMAIL 
//    ,A.TRADING_PSW
//    FROM SHP_COMMERCIAL_TENANT_INFO  A   WHERE A.COMM_TENANT_ID='" + msBsc.SvRef.UserInfo.OperDealerId.Split(',')[0] + @"'
//    ");


                        if (ds.Tables[0].Rows[0]["CONTACTS_EMAIL"].ToString() != this.GetParamHtValue("EMAIL"))
                        {
                            this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                            this.Alert("您输入的邮箱不是店铺绑定的邮箱，请重新录入！");
                            return;
                        }
                        if (ds.Tables[0].Rows[0]["LOGIN_PSWD"].ToString() != msBsc.AppLogic.Cfg.DesCry.encMe(this.GetParamHtValue("txtLoginPws"), "zbhpass"))
                        {
                            this.Alert("您输入的登录密码不正确，请重新录入！");
                            return;
                        }
                    }

                    string strcontent = "";
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "Template\\SysPwsReset.htm", System.Text.Encoding.Default))
                    {
                        strcontent = sr.ReadToEnd();
                    }
                    msBsc.AppLogic.Cfg.DesCry ooo=new AppLogic.Cfg.DesCry();
                    string strurl = msBsc.AppLogic.Cfg.DesCry.encMe(msBsc.SvRef.UserInfo.OperDealerId.Split(',')[0] + "," + this.GetParamHtValue("EMAIL") + "," + DateTime.Now.ToString(), "rmdes");
                    strurl = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.httpUrlBase + "d_ShopForgetTradPwsReset.htm?KEY=" + strurl;

                    strcontent = strcontent.Replace("{RESETPWS_MAIL_USER_NME}", msBsc.SvRef.UserInfo.OperDealerId.Split(',')[1]).Replace("{RESETPWS_MAIL_URL}", strurl);
                    msBsc.SvRef.SendEMail oSendEMail = new SvRef.SendEMail();
                    oSendEMail.SendEmailTo(msBsc.SvRef.UserInfo.OperDealerId.Split(',')[1], this.GetParamHtValue("EMAIL"), "优速购商城的商家交易密码重置申请确认！", strcontent);
                    //this.ExecJScript("debugger;");
                    //this.ExecJScript("LS.set('CURR_REG_MAIL','" + this.GetParamHtValue("EMAIL") + "');");
                    //this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "','STEP1');");
                    //this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "_RDT','"+DateTime.Now.ToString()+"');");
                    //this.ExecJScript("window.location.href = '/c_RegMailSend.htm';");

                    SetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, null, "2");
                    this.ExecJScript("$('#divInputInfo').hide();");
                    this.ExecJScript("$('#divMailSend').show();");
                }
            } 
        }

    }
}